-- LG update lock change and bad instalations (from 106.0) correction -- spustit
<g>
alter procedure dbo.IncGenerator @genid nvarchar(250),@useric bigint,@useru int as
declare @ic bigint
declare @u int
declare @value bigint
begin
  set nocount on
  select @ic = ic,@u = u from a165u0 where a285u0 = @genid  
  if @@rowcount = 1
  begin
    select @value = a287u0 from a165u0 with(updlock) where ic = @ic and u = @u
	if @@rowcount = 1
    begin
      set @value = @value + 1
      update a165u0 set a287u0 = @value,ts0 = getdate(),useric = @useric,useru = @useru where ic = @ic and u = @u
	end else set @value = -1
  end else set @value = -1
  set nocount off
  select @value
end
</g>

--LuP: plneni udaje "Skladovy doklad" na rezervacni vazbe a v rozpadu polozky (NESPOUSTET)
<g>
update a371708u10 set a40327683u10 = null where a40327683u10 is not null
update REZ set a40327683u10 = 1 
from a371708u10 as REZ
join a38794u10 as POL on (POL.ic = REZ.ic_a and POL.u = REZ.u_a)
where a27465296u10 is not null and a27465296u10 <> 0
</g>

<g>
update a234235u10 set a40327822u10 = null where a40327822u10 is not null
update RA set a40327822u10 = 1
from a234235u10 as RA 
join a29555u10 as POL on (POL.ic = RA.ic_a and POL.u = RA.u_a)
join a371708u10 as REZ on (REZ. ic_a = POL.ic and REZ. u_a = POL.u)
where REZ.a40327683u10 = 1
</g>

--LuP: vymaz rezervacnich vazeb s udajem "Na vydeji" pro neskladove doklady (NESPOUSTET)
<g>
delete from a371708u10 where a27465296u10 is not null and a40327683u10 is null
</g>

--LuP: nulovani udaje "Na vydeji - pomocny" v rozpadu polozky dle RA - pro polozky neskladovych dokladu (NESPOUSTET)
<g>
update a234235u10 set a27464517u10 = null
where a27464517u10 is not null and a40327822u10 is null
</g>

--LuP: plneni udaje "Na vydeji" ve stavech zasob a stavech zasob s RA (NESPOUSTET)
<g>
update a38243u10 set a40327685u10 = a27464490u10 where a27464490u10 is not null
update a234238u10 set a40327754u10 = a27464493u10 where a27464493u10 is not null
</g>
